//
//  RHReporDataCell.m
//  RuiHeApp
//
//  Created by Yan Chen on 2024/11/15.
//

#import "RHReportDataCell.h"
#import "RHReportDataModel.h"

@interface RHReportDataCell()

@property (nonatomic, strong) RHReportDataModel *model;

@property (nonatomic, strong) QMUILabel *chgLab;

@property (nonatomic, strong) QMUILabel *dchgLab;

@property (nonatomic, strong) QMUILabel *socLab;

@property (nonatomic, strong) QMUILabel *timeLab;

@end
@implementation RHReportDataCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        [self setupUI];
    }
    return self;
}

-(void)setModel:(RHReportDataModel*)model lastModel:(RHReportDataModel*)lastModel type:(NSInteger)typeIndex
{
    _model = model;
    if (typeIndex == 0) {
        self.chgLab.text = [NSDecimalNumber decimalStringWithDoubleString:model.charge nullStr:@"0"];
        self.dchgLab.text = [NSDecimalNumber decimalStringWithDoubleString:model.discharge nullStr:@"0"];
    }else{
        self.chgLab.text = [NSDecimalNumber decimalStringWithDoubleString:model.accumulationCharge nullStr:@"0"];
        self.dchgLab.text = [NSDecimalNumber decimalStringWithDoubleString:model.accumulationDisCharge nullStr:@"0"];
    }
    self.socLab.text = [NSDecimalNumber decimalStringWithDoubleString:model.soc nullStr:@"0"];
    
    NSString *startTime = [NSDate dateStringWithTimeInterval:model.ts/1000 formatter:@"HH:mm"];
    NSString *endTime = [NSDate dateStringWithTimeInterval:lastModel.ts/1000 formatter:@"HH:mm"];
    
    self.timeLab.text = startTime;
    
}

- (void)setupUI{
    kWeakSelf;
    [self setBackgroundColor:UIColor.clearColor];
    [self.contentView setBackgroundColor:CFTabViewBgColor];
    
    
    UIView *bgView = [[UIView alloc] init];
    [bgView setBackgroundColor:UIColor.whiteColor];
    [self.contentView addSubview:bgView];
    self.bgView = bgView;
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets(UIEdgeInsetsMake(0, 15, 0, 15));
        make.height.offset(35);
    }];
    CGFloat labWidth = (kUI_WINDOW_W - 30 -20)/4;
    for (int i = 0; i<4; i++) {
        QMUILabel *lab = [QMUILabel labelWithText:@"--" font:kSYSTEMFONT(13) textColor:kCOLOR_HEX_A(@"#171A1D", 0.6)];
        lab.adjustsFontSizeToFitWidth = YES;
        lab.minimumScaleFactor = 0.8;
        lab.textAlignment = NSTextAlignmentCenter;
        lab.tag = 100 + i;
        lab.numberOfLines = 2;
        [bgView addSubview:lab];
        [lab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.offset(i*labWidth+10);
            make.centerY.mas_offset(0);
            make.width.offset(labWidth);
        }];
    }
    self.timeLab = [bgView viewWithTag:100];
    self.chgLab  = [bgView viewWithTag:101];
    self.dchgLab = [bgView viewWithTag:102];
    self.socLab = [bgView viewWithTag:103];
}
@end
